import { request } from './request.js';

import { obj2query } from './utils.js';

export const userApis = {
    // 注册
    register: (data) => {
        return request('/upms/user/register', 'post', data);
    },
    // 用户验证码登录
    loginByVerificationCode: (data) => {
        return request('/auth/phone/token/sms' + obj2query(data), 'post');
    },
    // 用户名密码登录
    loginByPassword: (data) => {
        return request('/auth/oauth/token' + obj2query(data), 'post', data);
    },
    //修改密码
    editPassword: (data) => {
        return request('/upms/user/password', 'put', data);
    },
    //重置密码
    resetPassword: (data) => {
        return request('/upms/user/password/reset', 'put', data);
    },
    //查询小区
    searchCommunity: (data) => {
        return request('/agentmerchantadmin/area/community', 'get', data);
    },

    // 获取注册身份信息
    getIdentityType: () => {
        return request('/upms/dict/type/agent_identity_type', 'get');
    },

    // 获取图形验证码
    getValidateCode: (data) => {
        return request('/auth/validate/code/text', 'get', data);
    },
    // 获取手机验证码
    getVerificationCode: (data) => {
        return request('/upms/phone/code/no_graph_code' + obj2query(data), 'put');
    },
    // 注册后更新信息
    updateUserInfomation: (data) => {
        return request('/agentmerchantadmin/user/base/info', 'patch', data);
    },
    // 获取用户信息
    getUserInfo: () => {
        return request('/upms/user/info', 'get');
    },
    // 获取用户信息
    getUserInfo2: () => {
        return request('/agentmerchantadmin/user/base', 'get');
    },
    // 实名认证
    userAuthentication: (data) => {
        return request('/agentmerchantadmin/user/base/id_card/authentication', 'patch', data);
    },

    // 获取企业信息 省公司
    getCompanyInfo: () => {
        return request('/agentmerchantadmin/user/company', 'get');
    },
    // 更新企业信息信息
    updateCompanyInfomation: (data) => {
        return request('/agentmerchantadmin/user/company/company', 'patch', data);
    },

    // 更新银行公户信息
    updateCompanyBankInfomation: (data) => {
        return request('/agentmerchantadmin/user/company/bank', 'patch', data);
    },

    //获取分账系统银行
    getBankList: (data) => {
        return request('/agentmerchantadmin/user/company/xmtr/bank_config', 'get', data);
    },

    // 获取推广二维码
    getQRCode: () => {
        return request('/agentmerchantadmin/wxqrcode/unlimited', 'post');
    },
    // 获取银行卡信息
    getBankDetail: () => {
        return request('/agentmerchantadmin/user/base/bank', 'get');
    },
    // 修改设置银行卡信息
    updateBankDetail: (data) => {
        return request('/agentmerchantadmin/user/base/bank', 'patch', data);
    },
    // 退出登录
    logout: () => {
        return request('/auth/token/logout', 'delete');
    },

    // 获取客户列表
    getCustomerList: (data) => {
        return request('/agentmerchantadmin/user/base/client/list', 'get', data);
    },
    // 获取运营中心列表
    getYYList: (data) => {
        return request('/agentmerchantadmin/user/base/province/operation/list', 'get', data);
    },

    // 获取我的推荐列表
    getRecommendList: (data) => {
        return request('/agentmerchantadmin/user/link/my/recommend/list', 'get', data);
    },
    // 删除账户
    delAccount: () => {
        return request('/upms/user/editStatus', 'get');
    },
    // 删除账户
    checkPSD: (psd) => {
        return request('/upms/user/passwordmate?password=' + psd, 'get');
    }
};

export const homeApis = {
    /*
    地推角色数据查询
    ---------------------------
    */

    // 地推当天收益查询
    getTodayIncome_DT: () => {
        return request('/agentmerchantadmin/user/statistics/ground_promotion/earnings', 'get');
    },
    // 地推推广人数统计 柱形图数据
    getPeopleNum_DT: () => {
        return request('/agentmerchantadmin/user/statistics/ground_promotion/promoter_num', 'get');
    },
    // 地推推广佣金收益统计 柱形图数据
    getBrokerage_DT: () => {
        return request('/agentmerchantadmin/user/statistics/ground_promotion/brokerage', 'get');
    },

    /*
    管家角色数据查询
    ---------------------------
    */
    // 管家当天收益查询
    getTodayIncome_GJ: () => {
        return request('/agentmerchantadmin/user/statistics/steward/earnings', 'get');
    },
    // 管家订单收益统计 柱形图数据
    getBrokerage_GJ: () => {
        return request('/agentmerchantadmin/user/statistics/steward/brokerage', 'get');
    },
    // 管家推广收益统计 柱形图数据
    getRecommended_GJ: () => {
        return request('/agentmerchantadmin/user/statistics/steward/recommended', 'get');
    },

    /*
    运营角色数据查询
    ---------------------------
    */
    // 运营当天收益
    getTodayIncome_YY: () => {
        return request('/agentmerchantadmin/user/statistics/operator/earnings', 'get');
    },
    // 运营订单收益统计 柱形图数据
    getBrokerage_YY: () => {
        return request('/agentmerchantadmin/user/statistics/operator/brokerage', 'get');
    },
    // 运营提成收益统计(推荐收益) 柱形图数据
    getRecommended_YY: () => {
        return request('/agentmerchantadmin/user/statistics/operator/recommended', 'get');
    },

    /*
    省级代理角色数据查询
    ---------------------------
    */
    // 省代当天收益
    getTodayIncome_SD: () => {
        return request('/agentmerchantadmin/user/statistics/province/earnings', 'get');
    },
    // 省代订单收益统计 柱形图数据
    getBrokerage_SD: () => {
        return request('/agentmerchantadmin/user/statistics/province/brokerage', 'get');
    },
    // 省代提成收益统计(推荐收益) 柱形图数据
    getRecommended_SD: () => {
        return request('/agentmerchantadmin/user/statistics/province/recommended', 'get');
    },

    // 管家列表查询
    getGJList: (data) => {
        return request('/agentmerchantadmin/steward/list', 'get', data);
    },
    //管家详情
    getGJDetail: (data) => {
        return request('/agentmerchantadmin/steward/detail/' + data, 'get');
    },

    //管家转让
    changeGJ: (data) => {
        return request('/agentmerchantadmin/steward/transfer/community', 'post', data);
    },

    // 帮手列表查询
    getBSList: (data) => {
        return request('/agentmerchantadmin/rider/user/list', 'get', data);
    },
    //帮手详情
    getBSDetail: (data) => {
        return request('/agentmerchantadmin/rider/user/detail/' + data, 'get');
    },

    //帮手订单列表
    getRiderOrderList: (data) => {
        return request('/agentmerchantadmin/rider/order/list', 'get', data);
    },
    //帮手订单详情
    getRiderOrderDetail: (data) => {
        return request('/agentmerchantadmin/rider/order/detail/' + data, 'get');
    },
    //帮手订单更换帮手
    RiderOrderUpdate: (data) => {
        return request('/agentmerchantadmin/rider/order/change_rider', 'patch', data);
    },

    /*
    团队数据查询
    ---------------------------
    */
    //获取团队人数
    getTeamNum: () => {
        return request('/agentmerchantadmin/user/base/team/member/num', 'get');
    },
    //获取缴费情况
    getAgencyPayment: () => {
        return request('/agentmerchantadmin/user/base/agency/payment', 'get');
    },
    //获取团队奖金池
    getGroupPoolMoney: () => {
        return request('/agentmerchantadmin/user/base/bonus/pool', 'get');
    },
    //获取我的团队成员
    getOwnTeam: () => {
        return request('/agentmerchantadmin/user/link/my/team/members', 'get');
    },
    //获取我加入的团队成员
    getMyJoinTeam: (data) => {
        return request('/agentmerchantadmin/user/link/join/team/members', 'get', data);
    }
};

export const financeApis = {
    // 获取钱包信息
    getWalletInfo: () => {
        return request('/agentmerchantadmin/wallet', 'get');
    },
    // 获取cbt收入明细
    getCBTList: (data) => {
        return request('/agentmerchantadmin/wallet/cbt', 'get', data);
    },
    // 获取提成收入明细
    getCommissionList: (data) => {
        return request('/agentmerchantadmin/wallet/royalty', 'get', data);
    },
    // 获取提现明细
    getWithdrawalList: (data) => {
        return request('/agentmerchantadmin/wallet/withdrawal', 'get', data);
    },

    //申请提现
    withdrawalSubmit: (data) => {
        return request('/agentmerchantadmin/withdrawal/apply', 'post', data);
    },
    //CBT转换
    CBTtoMoneySubmit: (data) => {
        return request('/agentmerchantadmin/withdrawal/cbt/convert', 'post', data);
    },
    //获取地推客户转cbt列表
    getPromotionUserList: (data) => {
        return request('/agentmerchantadmin/wallet/ground_promotion/client_transfer/cbt', 'get', data);
    },
    //获取今日可转CBT数量
    getTodayTransformCBT: () => {
        return request('/agentmerchantadmin/withdrawal/cbt/convert/enable', 'get');
    },
    //获取广告链接
    getADurl: (get) => {
        return request('/advertisers/loopnext', 'get');
    },

    //支付宝支付
    zfbPay: (data) => {
        return request('/agentmerchantadmin/user/pay/create/order', 'post', data);
    },

    //广告数量增加
    adNumAdd: (data) => {
        return request('/agentmerchantadmin/playlog/report', 'post', data);
    }
};
export const commonApis = {
    // 获取省市区下级
    getArea: (data) => {
        return request('/agentmerchantadmin/area/sub_area', 'get', data);
    },

    verifyPhone: (data) => {
        return request('/upms/user/count', 'get', data);
    },

    getAppVersion: () => {
        return request('/agentmerchantadmin/api/app/version/getUpgradeData', 'get');
    },
    whitelistValidate: (phone: string) => {
        return request(`/agentmerchantadmin/phone/whitelist/validate1/${phone}`, 'get');
    },
    whitelistValidate2: (phone: string) => {
        return request(`/agentmerchantadmin/phone/whitelist/promotionValidate/${phone}`, 'get');
    },

    getIosShowHideFlag: () => {
        return request(`/upms/dict/type/agent_review_status`, 'get');
    },

    getPayMethods: () => {
        return request(`/upms/dict/type/agent_bank`, 'get');
    },
    getOssTempCredential: (data) => {
        return request(`/upms/file/getOssTempCredential`, 'post', data);
    }
};

export const getUserInfoMethod = async () => {
    let res = await userApis.getUserInfo();
    let res2 = await userApis.getUserInfo2();

    let flag = uni.getStorageSync('isRegisterFlag');

    let userRole: any;

    if (flag) {
        userRole = uni.getStorageSync('userRole');
        uni.setStorageSync('isRegisterFlag', false);
    } else {
        userRole = uni.getStorageSync('userRole') ? uni.getStorageSync('userRole') : res2.data.identityPermissionsList.slice(-1)[0];
    }

    let obj = {
        ...res.data.sysUser,
        grade: res2.data.grade,
        identityType: userRole,
        identityPermissionsList: res2.data.identityPermissionsList,
        inviteCode: res2.data.inviteCode,
        authentication: {
            authenticationAnnexBack: res2.data.authenticationAnnexBack,
            authenticationAnnexFront: res2.data.authenticationAnnexFront,
            authenticationIdCard: res2.data.authenticationIdCard,
            authenticationName: res2.data.authenticationName,
            authenticationNotes: res2.data.authenticationNotes,
            authenticationStatus: res2.data.authenticationStatus
        }
    };

    uni.setStorageSync('userInfomation', JSON.stringify(obj));
    uni.setStorageSync('userRole', userRole);
};
